<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-3-17
 * Time: 下午3:46
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Balance_detail_model extends MY_Model
{
    protected $table = 'balance_detail';
    //状态说明
    public function status_desc(&$data,$type=true) {
        //type : 1 赞赏支出 2 赞赏收入 3 悬赏发布押金 4 指派补差价 5 悬赏收入 6 悬赏全额退回 7 悬赏差价退回 8 提现 9 充值
        //status : 1 成功 2 冻结(发布需求完押金冻结) 3 申请中 4 失败 5 任务关闭已退回（悬赏支出）6 任务关闭退回（悬赏退回）7差价冻结
        //pay_ways : 1 微信 2 支付宝 3 余额
        $data_type = $data['type'];
        $data_status = $data['status'];
        $data_pays = $data['pay_ways'];
        if($type) {
            switch($data['type']) {
                case 1:
                    $data['type'] = '赞赏支出';
                    break;
                case 2:
                    $data['type'] = '赞赏收入';
                    break;
                case 3:
                    $data['type'] = '悬赏发布押金';
                    break;
                case 4:
                    $data['type'] = '指派补差价';
                    break;
                case 5:
                    $data['type'] = '悬赏收入';
                    break;
                case 6:
                    $data['type'] = '悬赏全额退回';
                    break;
                case 7:
                    $data['type'] = '悬赏差价退回';
                    break;
                case 8:
                    $data['type'] = '提现';
                    break;
                case 9:
                    $data['type'] = '充值';
                    break;

            }
        }

        switch($data['status']) {
            case 1:
                $data['status'] = '成功';
                break;
            case 2:
                $data['status'] = '冻结';
                break;
            case 3:
                $data['status'] = '申请提现';
                break;
            case 4:
                $data['status'] = '失败';
                break;
            case 5:
                $data['status'] = '任务关闭已退回';
                break;
            case 6:
                $data['status'] = '任务关闭退回';
                break;
            case 7:
                $data['status'] = '差价冻结';
                break;
        }
        switch($data['pay_ways']) {
            case 1:
                $data['pay_ways'] = '微信';
                break;
            case 2:
                $data['pay_ways'] = '支付宝';
                break;
            case 3:
                $data['pay_ways'] = '余额';
                break;
        }
        $data['type_id'] = $data_type;
        $data['status_id'] = $data_status;
        $data['pay_id'] = $data_pays;
        return $data;
    }
    public function set($id,$arr)
    {
        $this->db->set($arr)
            -> where(array('id'=>$id))
            -> update($this->table);
        return $this->db->affected_rows();
    }
}